<?php
class wiew {
	//  wiew
	public $base;
	public $themeBase;
	public $themeDir;
	public $id;
	
	// Template
	public $config;
    public  $vars;
    public  $foreachVars;
    private $tpl;
    private $content;
    private $fileName;
    private $compile;
    private $cache;
    private $compileDir;
    private $cacheDir;
    private $useCache   =   TRUE;
	
	private $w;
	
	public function __construct($theme, $id) {
		$this->id		 = $id;
		$this->base		 = config::get('System', 'base');
		$this->themeBase = $this->base.'static/themes/'.$theme.'/';
		$this->themeDir  = THEME_DIR.$theme.DS;
		$this->vars = (object) NULL;
	}
	
	/*public function Startob() {
		ob_start();
	}
	
	public function Stopob() {
		$routput = ob_get_contents();
		ob_end_clean();
	}*/
	
	public function setContent($w) {
		$this->vars	= $w->vars;
		$this->w	= $w;
	}
	
	public function display() {
		$tpl = file_get_contents($this->themeDir.'templates'.DS.'index.html');
		$tpl = str_replace('{ThemeBaseDir}', $this->themeBase, $tpl);
		$tpl = str_replace('{BaseDir}', $this->base, $tpl);
		$tab = array (
                '0' => $this->w->content,
                '1' => $this
         );
		System::load('wiew.compiler');
		$compiler = new compiler($tab);
        file_put_contents($this->id.'.php', $compiler->fetch());
		ob_start();
        include $this->id.'.php';
		$output = ob_get_contents();
		ob_end_clean();
		$tpl = str_replace('{ModContent}', $output, $tpl);
		print($tpl);
	}
}

?>